﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWPF.Models.UserManagement
{
    public interface IUser
    {

        UserContext User { get; set; }

        /// <summary>
        /// 初始化数据库
        /// </summary>
        void LoadDB(UserDbContext UserDb);

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="User"></param>
        /// <returns></returns>
        bool Login(UserContext User);

        /// <summary>
        /// 添加用户
        /// </summary>
        bool AddUser(UserContext User);

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="User"></param>
        void RemoveUser(UserContext User);

        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="User"></param>
        void ModifyUser(UserContext User);

        /// <summary>
        /// 输入用户，通过用户等级返回所有小于等于该等级的用户
        /// </summary>
        /// <param name="User"></param>
        /// <returns></returns>
        DataTable GetUser_Level(UserContext User);

        /// <summary>
        /// 输入用户，通过用户名称返回该用户信息
        /// </summary>
        /// <param name="User"></param>
        /// <returns></returns>
        DataTable GetUser_UserName(UserContext User);
        /// <summary>
        /// 输入用户，通过用户名称和密码返回该用户信息
        /// </summary>
        /// <param name="User"></param>
        /// <returns></returns>
        DataTable GetUser_Password(UserContext User);

        /// <summary>
        /// 输入用户，通过用户等级返回所有小于等于该等级的用户
        /// </summary>
        /// <param name="User"></param>
        /// <returns></returns>
        UserContext[] GetUserStruct_Level(UserContext User);

        /// <summary>
        /// 输入用户，通过用户名称返回该用户信息
        /// </summary>
        /// <param name="User"></param>
        /// <returns></returns>
        UserContext[] GetUserStruct_UserName(UserContext User);
        /// <summary>
        /// 输入用户，通过用户名称和密码返回该用户信息
        /// </summary>
        /// <param name="User"></param>
        /// <returns></returns>
        UserContext[] GetUserStruct_Password(UserContext User);
    }

    public class UserContext
    {
        public UserContext()
        {
            PowerLevel = 0;
            Errors = 0;
        }
        /// <summary>
        /// ID字段
        /// </summary>
        public LiteDB.ObjectId _id { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// 权限
        /// </summary>
        public UserPower Power { get; set; }

        /// <summary>
        /// 权限等级
        /// </summary>
        public int PowerLevel { get; set; }

        /// <summary>
        /// 用户最后登录时间
        /// </summary>
        public DateTime LastLoginTime { get; set; }

        /// <summary>
        /// 注册时间
        /// </summary>
        public DateTime RegistrationTime { get; set; }

        /// <summary>
        /// 输错密码次数
        /// </summary>
        public int Errors { get; set; }

        /// <summary>
        /// 输错密码时间
        /// </summary>
        public DateTime ErrorTime { get; set; }

        /// <summary>
        /// 方案
        /// </summary>
        public Scheme Scheme { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remarks { get; set; }

    }

    public class UserDbContext
    {
        /// <summary>
        /// 数据库路径，不包含数据库后缀
        /// </summary>
        public string Path { get; set; }

        /// <summary>
        /// 数据库名称
        /// </summary>
        public string DbName { get; set; }

        /// <summary>
        /// 数据库密码
        /// </summary>
        public string Password { get; set; }
    }

    public enum UserPower
    {
        None,
        Tourist,//游客
        Operator,//操作员
        Engineer,//工程师
        Administrator//管理员
    }

    public enum Scheme
    {

    }

    public enum State
    {
        登录成功,
        账户或密码错误,
        当前账户已锁定
    }
}
